#include <iostream>
#include <sys/epoll.h>
#include "mylog.hpp"
#include "common.hpp"
#include "Addr.hpp"
int defaultfd = -1;
using namespace my_log;
class Epoller
{
public:
    Epoller()
        : _epfd(defaultfd)
    {
        // 创建一个进程epoll模型
        _epfd = epoll_create(128);
        if (_epfd < 0)
        {
            LOG(LogLevel::FATAL) << "epoll_create error...";
            exit(epoll_create_err);
        }
    }
    int Epfd()
    {
        return _epfd;
    }
    // 下边是对epoll进行增删改的操作函数
    void AddEvent(int fd, uint32_t events)
    {
        // 将其设置进入内核
        struct epoll_event ev;
        ev.data.fd = fd;
        ev.events = events;
        int n = epoll_ctl(_epfd, EPOLL_CTL_ADD, fd, &ev);
        if(n<0)
        {
            LOG(LogLevel::ERROR)<<"epoll_ctl error...";
        }
    }
    void DelEvent()
    {
    }
    void ModEvent()
    {
    }
    void WaitEvent()
    {
    }
    ~Epoller()
    {
        if (_epfd > 0)
        {
            close(_epfd);
        }
    }

private:
    int _epfd;
};